package com.ali.juejin.widget

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.databinding.InverseBindingAdapter
import androidx.databinding.InverseBindingListener
import androidx.lifecycle.MutableLiveData
import com.ali.juejin.R
import com.blankj.utilcode.util.LogUtils

class TagView : androidx.appcompat.widget.AppCompatTextView {
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    )

    companion object {

        @BindingAdapter("selectedTag","tagId")
        @JvmStatic
        fun setSelectedTag(view: TextView, selectedTag:Int, tagId:Int){
//        LogUtils.wTag("选中的tag",selectedTag)
//        LogUtils.wTag("当前的tag",view.text)
            val resources = view.context.resources
            if (selectedTag == tagId){

                view.background = resources.getDrawable(R.drawable.tag_border_selected)
                view.setTextColor(Color.parseColor("#ffffff"))
            }else{
                view.background = resources.getDrawable(R.drawable.tag_border_unselected)
                view.setTextColor(Color.parseColor("#BAC2CB"))
            }
        }
    }


}